import requests
import json


def get_page(page):
    url = 'http://www.u17.com/comic/ajax.php?mod=comic_list&act=comic_list_new_fun&a=get_comic_list'
    headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    }
    data = {"data[group_id]": "no", "data[theme_id]": "no", "data[is_vip]": "no", "data[accredit]": "no",
            "data[color]": "no", "data[comic_type]": "no", "data[series_status]": "no", "data[order]": "2",
            "data[page_num]": "1", "data[read_mode]": "no"}

    data["data[page_num]"] = str(page)
    # 构建一个表单提交的请求方式
    response = requests.post(url, headers=headers, data=data)
    return response.text


def parse_page(html):
    json_data = json.loads(html)
    # print(json_data)
    comic_list = json_data['comic_list']
    for comic in comic_list:
        print(comic['name'])
    print('完了')

def main():
    for page in range(1, 100):
        print(page)
        html = get_page(page)
        parse_page(html)


if __name__ == '__main__':
    main()